import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
const $time 	= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		forms : [
			{ label: '标本条码',		name: 'spec_code' },
			{ label: '实验号',		name: 'experiment_num' },
			{ label: '科室',  		name: 'parent_project_id', type:'select', idStr:'uuid' },
			{ label: '岗位',  		name: 'project_id', type:'select' },
			{ label: '项目名称',		name: 'kind_id', type:'select'  },
			{ label: '领取时间',		names:['start_date','end_date'], name: 'jz-time', type:'date-range' },
			
		],
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		this.onTime()
	}
	onTime = reset => {
		// 设置时间默认值
		$time.then(f=>{
			const arr = f.duration['7']()
			this.resetModel = { start_date: arr[0], end_date: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			if(reset){
				this.searchFormRef.setValue({'jz-time': [ this.model.start_date, this.model.end_date ] })
			}
			this.fetch()
		})
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 状态
			$fn.setRow(forms, 'parent_project_id',  await f.getCache({ api:'ke_shi' }))
			// 岗位
			$fn.setRow(forms, 'project_id',  await f.getCache({ api:'gang_wei' }))
			// 项目名称
			$fn.setRow(forms, 'kind_id',  await f.getCache({ api:'nature_project' }))
			//
			this.setState({ forms })
		})
	}
	
	load = rows => {
		if(rows){
			this.resetModel = {}
			this.query = { conf_report_date_id: rows.uuid, start_date:'', end_date:'' }
			this.searchFormRef.reset()
			this.fetch()
		}else{
			this.query = { conf_report_date_id:''}
			this.onTime(true)
		}
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'conf-report-date/tslists')
	
	// 表单
	cols = [
		{ title: '条码号',		dataIndex: 'spec_code', 			...$fn.table.spec_code },
		{ title: '实验号', 		dataIndex: 'experiment_num', 		...$fn.table.exp_num },
		{ title: '科室', 		dataIndex: 'parent_project_name', 	width:200 },
		{ title: '岗位', 		dataIndex: 'project_name', 			width:200 },
		{ title: '项目',		dataIndex: 'kind_name', 			width:200 },
		{ title: '领取时间', 	dataIndex: 'created_at', 			...$fn.table.time }
	]
	
	render(){
		return (
			<>
				{/* 搜索 */}
				{ SearchForm.call(this, { noRefresh:true, timeStr:'7' }) }
				{/* 表格 */}
				{ Table.call(this) }
			</>
		)
	}
}

export default Index